package com.inspur.iaic.service;

import java.util.concurrent.BlockingQueue;

import com.inspur.iaic.data.NginxLog;

/**
 * 日志处理器，缓存最近capacity个日志信息
 *
 */
public abstract class LogProcessor {
	private BlockingQueue<NginxLog> nginxLogQueue;

	public void put(NginxLog log) {
		while (!nginxLogQueue.offer(log)) {
			nginxLogQueue.poll();
		}
		handle(log);
	}

	public abstract void handle(NginxLog log);

	public NginxLog[] getAll() {
		NginxLog[] all = new NginxLog[nginxLogQueue.size()];
		return nginxLogQueue.toArray(all);
	}

	public NginxLog get() {
		return nginxLogQueue.peek();
	}

	public BlockingQueue<NginxLog> getNginxLogQueue() {
		return nginxLogQueue;
	}

	public void setNginxLogQueue(BlockingQueue<NginxLog> nginxLogQueue) {
		this.nginxLogQueue = nginxLogQueue;
	}

}
